package com.hahaliu.hahaliu.im;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.Executor;

@Component  // 让 Spring 管理该类
@Slf4j
public class IMServerStarter {

	@Autowired
	@Qualifier("taskExecutor")  // 注入名为 taskExecutor 的线程池
	private Executor taskExecutor;

	// 启动 IMServer 的方法
	// 在 Spring 容器初始化后自动调用此方法
	@PostConstruct
	public void startIMServer() {
		// 提交任务到线程池中
		taskExecutor.execute(() -> {
			try {
				new IMServer().start();  // 启动 IMServer
			} catch (Exception e) {
				log.error("IMServer启动失败", e);  // 错误日志记录
			}
		});
	}
}
